#include <glib.h>

static gboolean eval_cb (const GMatchInfo *info, GString *res, gpointer data)
{
    gchar *match;
    gchar *r;

    match = g_match_info_fetch (info, 0);
    r = g_hash_table_lookup ((GHashTable *)data, match);
    g_string_append (res, r);
    g_free (match);

    return FALSE;
}

static void g_regex_replace_eval_test(void)
{
    GRegex *reg;
    GHashTable *h;
    gchar *res;

    gchar *ori = "a1b2c3d74A151B12C633";

    h = g_hash_table_new (g_str_hash, g_str_equal);

    g_hash_table_insert (h, "1", "ONE");
    g_hash_table_insert (h, "2", "TWO");
    g_hash_table_insert (h, "3", "THREE");
    g_hash_table_insert (h, "4", "FOUR");

    reg = g_regex_new ("1|2|3|4", 0, 0, NULL);
    res = g_regex_replace_eval (reg, ori, -1, 0, 0, eval_cb, h, NULL);

    g_print("ori:%s \n", ori);
    g_print("res:%s \n", res);

    g_free(res);

    g_hash_table_destroy (h);
    g_regex_unref(reg);

    return;
}

int main (int argc, char** argv)
{
    g_regex_replace_eval_test();

    return 0;
}